import 'package:duuchin/models/user_model.dart';
import 'package:flutter/cupertino.dart';

/// 歌曲列表模型
class SongList {
  /// 包含SongItem模型的一个集合
  final List<SongItem> list;

  SongList(this.list);

  /// 循环后台返回的数组 将每一项组装成 SongItem
  factory SongList.fromJson(List<dynamic> list) {
    return SongList(
      list.map((item) => SongItem.fromJson(item)).toList(),
    );
  }
}

/// 歌曲每一项的详情 / 模型
class SongItem {
  /// 此处定义数据表中的字段(或接口返回的)即可
  final int id;
  final int userId;
  final String coverPictureUrl;
  final String songUrl;
  final String cnName;
  final String enName;
  final int commentCount;
  final int thumbUpCount;
  final int readCount;
  final UserItem user;

  SongItem({
    @required this.id,
    @required this.userId,
    @required this.coverPictureUrl,
    @required this.songUrl,
    @required this.cnName,
    @required this.enName,
    @required this.commentCount,
    @required this.thumbUpCount,
    @required this.readCount,
    @required this.user,
  });

  /// 将json数组转换为实体模型
  factory SongItem.fromJson(dynamic item) {
    return SongItem(
      id: item['id'],
      userId: item['userId'],
      coverPictureUrl: item['coverPictureUrl'],
      songUrl: item['songUrl'],
      cnName: item['cnName'],
      enName: item['enName'],
      commentCount: item['commentCount'],
      thumbUpCount: item['thumbUpCount'],
      readCount: item['readCount'],
      user: UserItem.formJson(item['user']),
    );
  }
}
